import socket
import sys

server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(("", 5000))
server.listen(2)
server.setblocking(1)

print "TCPServer Waiting for client on port 5000"

while 1:
    client1, addr1 = server.accept()
    client2, addr2 = server.accept()

    print "I got a new connection from ", addr1
    print "I got a new connection from ", addr2

    while 1:
        try:
            data = client1.recv ( 512 )
        except:
            data = -1
            sys.exc_clear
        if data != -1:
            if data == "I Died":
                print "Robot 1 was defeated!!"
            else:
                client2.send(data)
                print "Robot 1 hit Robot 2 for ", data, "damage!"
            
        try:
            data2 = client2.recv (512)
        except:
            data2 = -1
            sys.exc_clear
        if data2 != -1:
            if data == "I Died":
                print "Robot 2 was defeated!!"
            else:
                client1.send(data)
                print "Robot 2 hit Robot 1 for ", data, "damage!"
